package com.ruoyi.controller.towComp.mechanics;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.SysParameterService;
import com.ruoyi.service.towComp.MechanicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/mechanics")
public class MechanicsController extends BaseController {

    @Autowired
    MechanicsService mechanicsService;

    @Autowired
    SysParameterService sysParameterService;

    private String prefix = "towComp/mechanics";


    @GetMapping()
    public String personnel() {
        return prefix + "/mechanics";
    }

    /**
     * 新增跳转
     *
     * @return
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("types",sysParameterService.findNameByType("第二工程公司机械类型"));
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map){
        return toAjax(mechanicsService.add(map));
    }



    /**
     * 修改跳转
     *
     * @return
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("types",sysParameterService.findNameByType("第二工程公司机械类型"));
        mmap.put("obj",mechanicsService.findMechanicsById(id));
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(mechanicsService.edit(map));
    }


    /**
     * 修改跳转
     *
     * @return
     */
    @GetMapping("/edit")
    public String edit() {
        return prefix + "/edit";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        startPage();
        return getDataTable(mechanicsService.findMechanics(map));
    }


    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(mechanicsService.remove(ids));
    }

}
